package com.whut.producer;

import com.whut.producer.pojo.Data_WD;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

@EnableScheduling
@SpringBootApplication
public class ProducerApplication {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    public static void main(String[] args) {
        SpringApplication.run(ProducerApplication.class, args);
    }

    @Scheduled(fixedRate = 10000)
    public void sendMessage(){
          /*
        生产100个数据，并存入一个List中
        */
        ArrayList<Data_WD> WD_List = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
            /*
            模拟65个温度数据，存入一个List中
             */
        for (int j = 0; j < 65; j++) {
            Data_WD data_wd=new  Data_WD(sdf.format(new Date()),Math.random()*10,"WD"+Math.round(Math.random()*1000));
            WD_List.add(data_wd);
        }

        rocketMQTemplate.convertAndSend("DATA_WD",WD_List );
    }
}
